<!DOCTYPE>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>权限管理</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/plugin/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/css/dj-css.css">
    <link rel="stylesheet" type="text/css" href="../../../page/common/css/oa_system.css">
</head>
<body>
<div id="createApp">

    <h2>权限管理</h2>

    <div class="main">
        <!--<h3>用户管理</h3>-->
        <div class="layui-form-pane">
            <button type="button" class="createFlow" @click="addpermissionadmin">添加权限
            </button>
        </div>
        <table class="" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th  width="33%">权限ID</th>
                <th width="33%">权限名</th>
                <th width="33%">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="task in depttasklist">
                <td v-text="task.pid"></td>
                <td v-text="task.permissionname"></td>
                <td class="operate">
                    <button @click="dealTask(task.pid)">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="layui-form-item clearfix footer">
            <div class="fl rowsPerPage ">
                每页显示 <input type="number" v-model="pageChange.rowCount">条，共 <span>{{pageChange.total}}</span>条
            </div>
            <div class="fl turnPage ">
                <span class="firstPage" @click="pageUpOrDown(1)">首页</span>
                <span class="prePage" @click="pageUpOrDown('prev')">上一页</span>
                <span class="selectPage"><input type="text" v-model="pageChange.current" value="1">/ <b>{{pageChange.pageNumber}}</b> </span>
                <span class="nextPage" @click="pageUpOrDown('next')">下一页</span>
                <span class="lastPage" @click="pageUpOrDown(pageChange.pageNumber)">末页</span>
                <span class="goPage" @click="init">确认</span>
            </div>
        </div>
    </div>
    <div class="mask" v-show="dealResultShowFlag" >
        <div class="dealResult">
            <h6>
                编辑角色信息
                <i @click="dealResultShowFlag = !dealResultShowFlag">×</i>
            </h6>
            <form class="" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">权限名：</label>
                    <div class="layui-input-inline">
                        <input type="text" v-model="dealResult.roleName" class="layui-input">
                    </div>
                </div>
            </form>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" @click="done()">完成</button>
            </div>
        </div>
    </div>
</div>
<script src="/static/lib/jquery.min.js"></script>
<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script src="/static/lib/vue.min.js"></script>
<script src="/static/lib/x-layui.js"></script>
<script src="/static/lib/dj-js.js"></script>
<script type="text/javascript">

    var VM = new Vue({
        el: "#createApp",
        created: function () {
            this.init();
            this.lay();
        },
        data: {
            parameter: {},
            pageChange: {
                current: 1,//当前页
                rowCount: 5,//每页5行
                total:"",
                pageNumber:""
            },
            depttasklist: [],
            taskId:"",
            dealResultShowFlag: false,
            dealResult: {},
            hasAdmin:[],
            roleList:[]
        },
        methods: {
            lay: function () {
                layui.use(['layer', "form", 'laydate'], function () {
                    var form = layui.form(),
                            layer = layui.layer,
                            laydate = layui.laydate;
                });
            },
            init: function () {
                var _this = this;
                $.ajax({
                    type: "post",
                    url: "../../system/permissions.do",
                    data: _this.pageChange,
                    dataType: "json",
                    success: function (data) {
                        if (data) {
                            _this.depttasklist = data.rows;
                            _this.pageChange.total = data.total;
                            _this.pageChange.pageNumber = Math.ceil(_this.pageChange.total/_this.pageChange.rowCount);
                        }

                    }
                });
            },
            addpermissionadmin:function(){
                this.dealResultShowFlag = true;
            },
            pageUpOrDown:function(type){
                if(isNaN(type)){
                    if(type == "prev"){
                        if(this.pageChange.current > 1){
                            this.pageChange.current--;
                        }
                    }
                    if(type == "next"){
                        if(this.pageChange.current < this.pageChange.pageNumber){
                            this.pageChange.current++;
                        }
                    }
                }else{
                    this.pageChange.current = type;
                }
            },
            verify: function (item) {
                if (item == "") {
                    layer.msg("必填项不能为空！", {icon: 5});
                    return false;
                }
            },
            sub: function () {
                var _this = this;
                this.parameter.leave_type = $("#leave_type").html();
                this.parameter.start_time = $("#LAY_demorange_s").val();
                this.parameter.end_time = $("#LAY_demorange_e").val();
                this.parameter.reason = $("#reason").val();
                $.ajax({
                    type: "post",
                    url: "../../activiti/startleave.do",
                    data: _this.parameter,
                    dataType: "json",
                    success: function (data) {
                        layer.msg("提交成功！", {icon: 1});
//                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
//                        parent.layer.close(index);
//                        parent.window.location.reload();
//                        window.location.href = "javascript:location.replace(location.href)";
                    }
                });
            },
            dealTask: function (taskId) {
                var _this = this;
                this.taskId = taskId;

                //询问框
                layer.confirm('确定删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "post",
                        url: "../../system/deletepermission.do",
                        data: {"pid": taskId},
                        dataType: "json",
                        complete:function(){
                            setTimeout(function () {
                                window.location.reload();
                            },100);
                        }
                    });
                });




            },
            done:function(){
                var _this = this;
                layui.use(['layer', "form", 'laydate'], function () {
                    var layer = layui.layer;
                });

                $.ajax({
                    type: "post",
                    url: "../../system/addpermission.do",
                    data:{"permissionname":_this.dealResult.roleName},
                    dataType: "json",
                    complete:function(){
                        setTimeout(function () {
                            _this.dealResultShowFlag = false;
                            window.location.reload();
                        },100);
                    }
                });
            },
            reset: function () {
                $("#leave_type").html("请选择请假类型");
                $("#leave_type").attr("selectedCode", "");
                $(".dj-select-list li").removeClass("selected");
                $("#LAY_demorange_s").val("");
                $("#LAY_demorange_e").val("");
                $("#reason").val("");
            }
        }
    });//vue 实例结束

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        $("#LAY_demorange_s").val(laydate.now());
        $("#LAY_demorange_e").val(laydate.now());
        var start = {
            min: laydate.now()
            , max: '2099-06-16 23:59:59'
            , istoday: false
            , choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas;//将结束日的初始值设定为开始日
            }
        };

        var end = {
            min: laydate.now()
            , max: '2099-06-16 23:59:59'
            , istoday: false
            , choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };


    });

</script>
</body>
</html>